package com.ujoku.service.impl;

import com.labillusion.core.database.base.mybatis.dao.BaseDao;
import com.labillusion.core.database.base.mybatis.service.base.impl.BaseServiceImpl;
import com.ujoku.dao.WineryDao;
import com.ujoku.domain.Winery;
import com.ujoku.service.CdnService;
import com.ujoku.service.WineryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Greg.Chen on 14-11-1.
 */
@Service
public class WineryServiceImpl extends BaseServiceImpl<Winery> implements WineryService<Winery> {

    @Autowired
    private WineryDao dao;

    @Override
    protected BaseDao<Winery> getBaseDao() {
        return this.dao;
    }

    @Autowired
    private CdnService cdnService;

    @Override
    public List<Winery> selectList(){
        List<Winery> list = super.selectList();
        for (Winery winery : list){

            List<String> imageList = new ArrayList<>();

            for(int i=0; i< 5;i++){
                String image = "winery/" + winery.getId() + "_" + i + ".jpg";

                imageList.add(cdnService.builder(image, winery.getUpdateTime().getTime()));
            }
            winery.setImageList(imageList);
        }

        return list;
    }

    @Override
    public int insert(Winery tag){

        return super.insert(tag);
    }

    @Override
    public int update(Winery tag){

        return super.update(tag);
    }

    @Override
    public int deleteById(int id){

        return super.deleteById(id);
    }
}
